package org.http;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.nio.channels.SocketChannel;

/**
 * @author andy
 */
@Slf4j
public class PrintInfo {

    private static PrintInfo printInfo = null;
    static PrintInfo of(){
        return null != printInfo ? printInfo : new PrintInfo();
    }

    /**
     * 打印IP和端口
     * @param socketChannel
     */
    void printInfo(SocketChannel socketChannel){
        if (log.isDebugEnabled()) {
            log.debug("Connection is {}:{}",
                    socketChannel.socket().getInetAddress().getHostAddress(),
                    socketChannel.socket().getPort());
        }
    }

    void printRemoteInfo(SocketChannel socketChannel) throws IOException {
        if (log.isDebugEnabled()) {
            log.debug("Connection is {}:{}:{}",
                    socketChannel.getRemoteAddress().toString().replace("/", ""),
                    socketChannel.socket().getRemoteSocketAddress().toString(),
                    socketChannel.socket().getPort());
        }
    }
}
